package com.yuand.aop;

import com.yuand.annotation.ParamVerify;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

/**
 * @author yuandong
 * @company KB
 * @create 2022-03-23 14:21
 */
@Component
@Aspect
public class ParamaAop {

	//定义切点 从这里开始切
	@Pointcut("@annotation(com.yuand.annotation.ParamVerify)")
	public void annotationPointCut(){}

	//这是切面方法
	@Before("annotationPointCut()")
	public void paramsAop(JoinPoint joinPoint){
		joinPoint.getTarget(); // 获取被代理的对象
		joinPoint.getThis(); // 获取代理对象自己

		Signature signature = joinPoint.getSignature();

		MethodSignature sign = (MethodSignature)joinPoint.getSignature();

		Method method = sign.getMethod();

		ParamVerify annotation=method.getAnnotation(ParamVerify.class);

		String methodName = joinPoint.getSignature().getName(); // 获取目标方法名
		String simpleName=joinPoint.getSignature().getDeclaringType().getSimpleName(); // 获取目标方法所属类的简单类名
		String fullName=joinPoint.getSignature().getDeclaringTypeName(); // 获取目标方法所属类的类名
		Object[] args = joinPoint.getArgs(); // 获取传入目标方法的参数，返回一个数组

	}
}
